Add IO#set_encoding_by_bom since 2.7.0#2275
Merged
znz merged 1 commit intorurema:masterfrom May 26, 2020
Merged
Conversation
pocke
commented
May 26, 2020
| 自身が BOM から始まる場合、BOM を読み進めて外部エンコーディングをセットし、セットしたエンコーディングを返します。 | ||
| BOM が見つからなかった場合は nil を返します。 | ||
|
|
||
| 自身がバイナリモードでないかすでにエンコーディングがセットされている場合、例外が発生します。 |
Member
Author
There was a problem hiding this comment.
実際にはArgumentErrorが発生するようですが、RDocの方に例外クラスが明示されていなかったので、るりまでもクラスは書かないようにしています
znz
approved these changes
May 26, 2020
Member
|
とりあえず良さそうだったのでマージしてしまいましたが、 UTF-8 以外 (UTF-16?) の例もあると良いかもしれません。 |
Member
Author
|
複数のエンコーディングの例があっても大して情報は増えない(BOMとエンコーディングが変わっただけで後は同じ)なので、足さなくていいかなと思っています。 一方、BOMのない非ASCII文字が含まれているテキストに対してset_encoding_by_bomを呼び出す例はあってもよいかなあと、コメントを受けて考えています |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#2071
Ruby 2.7 で追加された IO#set_encoding_by_bom のドキュメントを追加します。
RDoc: https://docs.ruby-lang.org/en/2.7.0/IO.html#method-i-set_encoding_by_bom
サンプルコードはRDocのものをベースに、
FIle.openにブロックを渡す形にしたり、読み込んだ文字列のencodingを明示したりしています。